<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    // let random = parseInt(Math.random() * 11);
    // let num = prompt("请输入一个0~10的整数：");
    function getRandom(N, M) {
      return Math.floor(Math.random() * (M - N + 1) + N);
    }
    // let random = getRandom(1, 10);
    let start = parseInt(prompt("请输入猜测起点："));
    let end = parseInt(prompt("请输入猜测终点："));
    let random = getRandom(start, end);
    console.log(random);
    while (true) {
      num = parseInt(prompt(`请输入一个${start}~${end}的整数：`));
      if (num < random) {
        alert("小了");
        continue;
      } else if (num > random) {
        alert("大了");
        continue;
      } else {
        alert("猜对了！")
        break;
      }
    }
  </script>
</body>

</html>